<extend name="Public:base"/>
<block name="title"> 武汉同兴一站办企业服务有限公司 管理中心 - 分类添加</block>

<block name="header">
    <span class="action-span"><a href="#">商品分类</a></span>
    <span class="action-span1"><a href="{:U('/index.php/Admin')}">武汉同兴一站办企业服务有限公司 管理中心</a></span>
    <span id="search_id" class="action-span1"> - 添加分类 </span>

    <div style="clear:both"></div>
</block>
<block name="body">

    <div class="tab-div">
        <div id="tabbar-div">
            <p>
                <span class="tab-front" id="general-tab">通用信息</span>
                <!--  <span class="tab-front" id="general-tab">商品属性</span>-->
                <span class="tab-front" id="general-tab">商品相册</span>
                <!--  <span class="tab-front" id="general-tab">商品规格</span>-->

            </p>
        </div>
        <div id="tabbody-div">
            <form  action="{:U('Goods/edit')}" id="my_form" method="post" enctype="multipart/form-data">

                <table width="90%" class="table" id="general-table" align="center">

                    <tr>
                        <td class="label">商品分类:</td>
                        <td>

                            <select name="class_id">
                                <option name="class_id" value="{$data[0]['class_id']}">{$data[0]['name']}</option>
                                <volist name="goods_class" id="vo">
                                    <option name="class_id" value="{$vo.class_id}">
                                        {$vo.lev|str_repeat="--",###}{$vo.name}
                                    </option>
                                </volist>
                            </select>
                        </td>
                    </tr>

                    <tr>
                        <td class="label">商品名称：</td>
                        <td><input type="text" name="goods_name" value="{$data[0]['goods_name']}" size="30"/>
                            <span class="require-field">*</span></td>
                    </tr>

                    <!-- <tr>
                         <td class="label">促销商品：</td>
                         <td>
                             促销价格：<input type="text" nane="cx_price" value="" size="20">
                             开始时间：<input type="text" nane="start" value="" size="20">
                             结束时间：<input type="text" nane="end" value="" size="20">


                         </td>
                     </tr>-->
                    <!-- <tr>
                     <td class="label">商品分类：</td>
                     <td>
                         <select name="cate_id">
                             <option value="0">|&#45;&#45;请选择</option>
                             <volist name="cate" id="vo">
                                 <option value="{$vo.id}">|{$vo.lev|str_repeat='&#45;&#45;',###}{$vo.cname}</option>
                             </volist>

                         </select>
                         <span class="require-field">*</span>
                     </td>
                 </tr>-->

                    <tr>
                        <td class="label">商品简介：</td>
                        <td>
                            <input type="text" name="goods_intro" value="{$data[0]['goods_intro']}" size="50"/>
                        </td>
                    </tr>

                    <!-- <tr>
                         <td class="label">商品属性：</td>
                         <td>
                             <input type="checkbox" name="attribute[]"  value="1" > 属性1
                             <input type="checkbox" name="attribute[]"  value="2" > 属性2
                             <input type="checkbox" name="attribute[]"  value="3" > 属性3

                         </td>
                     </tr>-->

                    <tr>
                        <td class="label">商品属性：</td>
                        <td>
                            <input type="button" name="addExtCate" id="addExtCate" value="增加扩展分类">

                            <volist name="data[0]['attributes']" id="att">
                                <select name="attribute[]">
                                    <option value="{$att['attribute_id']}">|&#45;&#45;{$att.value}</option>
                                    <volist name="atts" id="vo">
                                        <option name="attribute" value="{$vo['attribute_id']}">|{$vo.lev|str_repeat='&#45;&#45;',###}{$vo.value}</option>
                                    </volist>
                                </select>
                            </volist>
                        </td>
                    </tr>

                    <!--  <tr>
                          <td class="label">本店售价：</td>
                          <td>
                              <input type="text" name="shop_price" value="" size="20"/>
                              <span class="require-field">*</span>
                          </td>
                      </tr>-->
                    <tr>
                        <td class="label">是否上架：</td>
                        <td>
                            <input type="radio" name="state" value="1" <?= $data[0]['state'] == 1 ?"checked":""; ?> /> 是
                            <input type="radio" name="state" value="0" <?= $data[0]['state'] == 0 ?"checked":""; ?> /> 否
                        </td>
                    </tr>
                    <tr>
                        <td class="label">是否VIP商品：</td>
                        <td>
                            <input type="radio" name="vip_exclusive"
                                   value="0" <?= $data[0]['vip_exclusive'] == 0?"checked":""; ?> /> 普通商品
                            <input type="radio" name="vip_exclusive"
                                   value="1" <?= $data[0]['vip_exclusive'] == 1?"checked":""; ?> /> 1级会员商品
                            <input type="radio" name="vip_exclusive"
                                   value="2" <?= $data[0]['vip_exclusive'] == 2?"checked":""; ?> /> 2级会员商品
                            <input type="radio" name="vip_exclusive"
                                   value="3" <?= $data[0]['vip_exclusive'] == 3?"checked":""; ?> /> 3级会员商品
                            <input type="radio" name="vip_exclusive"
                                   value="4" <?= $data[0]['vip_exclusive'] == 4?"checked":""; ?> /> 4级会员商品
                            <input type="radio" name="vip_exclusive"
                                   value="5" <?= $data[0]['vip_exclusive'] == 5?"checked":""; ?> /> 5级会员商品
                            <input type="radio" name="vip_exclusive"
                                   value="6" <?= $data[0]['vip_exclusive'] == 6?"checked":""; ?> /> 6级会员商品
                        </td>
                    </tr>

                    <tr>
                        <td class="label">上级会员返利积分：</td>
                        <td>
                            <input type="text" name="superior_user_integral"
                                   value="{$data[0]['superior_user_integral']}" size="20"/>
                        </td>
                    </tr>

                    <tr>
                        <td class="label">上上级会员返利积分：</td>
                        <td>
                            <input type="text" name="supervisor_user_integral"
                                   value="{$data[0]['supervisor_user_integral']}" size="20"/>
                        </td>
                    </tr>

                    <!-- <tr>
                         <td class="label">地区:</td>
                         <td>

                             <select name="class_id">
                                 <option name="class_id" value="0"></option>
                                 <volist name="cate" id="vo">
                                     <option name="class_id" value="{$vo.class_id}">
                                         {$vo.lev|str_repeat="&#45;&#45;",###}{$vo.name}
                                     </option>
                                 </volist>
                             </select>
                         </td>
                     </tr>-->
                    <tr id="sss">
                        <td class="label">地区：</td>
                        <td>
                            <volist name="areas" id="ar">
                                <input type="checkbox" class="ssss{$ar.region_id}" name="region_id[]"
                                       region_name="{$ar.region_name}" value="{$ar.region_id}"
                                       onclick="alertMsg(this,{$ar.region_id})" <?= in_array( $ar['region_name'],$data[0]['areas'])?"checked":""; ?>
                                > {$ar.region_name}
                            </volist>

                        </td>
                    </tr>
                    <if condition="$data[0]['areas'][0] neq null ">

                        <volist name="data" id="datas">
                     <tr>
                         <td class="label">标准定价：</td>
                         <td>
                             <input type="checkbox" name="normal[{$datas['region_id']}]"  value="1"  <?= $datas['normal'] == 1?"checked":""; ?>> 是
                         </td>
                     </tr>

                     <tr>
                         <td class="label">初始价格：</td>
                         <td>
                             <input type="text" name="price[{$datas['region_id']}]" value="{$datas['price']}" size="20" />
                         </td>
                     </tr>

                     <tr>
                         <td class="label">VIP折扣：</td>
                         <td>

                             <div style="margin-top: 5px;">
                                 <b>普通折扣: </b><input type="text"  name="vip_discount[{$datas['region_id']}][]" value="{$datas['vip_discount'][0]}"  style="width: 130px;"/>
                             </div>
                             <div style="margin-top: 5px;">
                                 <b>VIP1折扣: </b><input type="text"  name="vip_discount[{$datas['region_id']}][]" value="{$datas['vip_discount'][1]}"  style="width: 130px;"/>
                             </div>
                             <div style="margin-top: 5px;">
                                 <b>VIP2折扣: </b><input type="text"  name="vip_discount[{$datas['region_id']}][]" value="{$datas['vip_discount'][2]}"  style="width: 130px;"/>
                             </div>
                             <div style="margin-top: 5px;">
                                 <b>VIP3折扣: </b><input type="text"  name="vip_discount[{$datas['region_id']}][]" value="{$datas['vip_discount'][3]}"  style="width: 130px;"/>
                             </div>
                             <div style="margin-top: 5px;">
                                 <b>VIP4折扣: </b><input type="text"  name="vip_discount[{$datas['region_id']}][]" value="{$datas['vip_discount'][4]}"  style="width: 130px;"/>
                             </div>
                             <div style="margin-top: 5px;">
                                 <b>VIP5折扣: </b><input type="text"  name="vip_discount[{$datas['region_id']}][]" value="{$datas['vip_discount'][5]}"  style="width: 130px;"/>
                             </div>
                             <div style="margin-top: 5px;">
                                 <b>VIP6折扣: </b><input type="text"  name="vip_discount[{$datas['region_id']}][]" value="{$datas['vip_discount'][6]}"  style="width: 130px;"/>
                             </div>
                         </td>
                     </tr>

                     <tr>
                         <td class="label">商品规格名:</td>
                         <td>
                             <div><input style="width: 200px" type="text"  name="spec_name[{$datas['region_id']}][]" value="{$datas['spec']['name']}" /></div>
                             <volist name="datas['spec']['option']" key="i" id="spec">
                             <div style="margin-top: 5px;">
                                 <b>规格值: </b><input type="text"  name="values[{$datas['region_id']}][]" value="{$spec['value']}"  style="width: 130px;"/>
                                 <b>价格: </b><input type="text"  name="prices[{$datas['region_id']}][]" value="{$spec['price']}"  style="width: 130px;"/>
                                 <b>可抵扣金额: </b><input type="text"  name="integral_price[{$datas['region_id']}][]" value="{$spec['integral_price']}"  style="width: 130px;"/>
                                 <b>是否可用: </b>
                                 <input type="checkbox" name="states[{$datas['region_id']}][]"  <?= $spec['states'] == 1?"checked":""; ?>  value="1" > 启用<!--  <input type="button" value="+" onclick="jia2box(this)">-->
                                 <if condition="$i eq 1"> <input type="button" value="+" onclick="jia2box(this)"> <else/> <input type="button" value="-" onclick="jian2box(this)"></if>
                             </div>
                             </volist>

                         </td>
                     </tr>
                            </volist>
                        </if>


                    <tr>
                        <td class="label">SEO页面标题：</td>
                        <td>
                            <input type="text" name="seo_title" value="{$data[0]['seo_title']}" size="20"/>
                        </td>
                    </tr>

                    <tr>
                        <td class="label">SEO页面关键词：</td>
                        <td>
                            <input type="text" name="seo_keywords" value="{$data[0]['seo_keywords']}" size="20"/>
                        </td>
                    </tr>

                    <tr>
                        <td class="label">SEO页面描述：</td>
                        <td>
                            <input type="text" name="seo_description" value="{$data[0]['seo_description']}" size="50"/>
                        </td>
                    </tr>

                    <tr>
                        <td class="label">商品详情：</td>
                        <td>
                            <script type="text/javascript" charset="utf-8"
                                    src="__PUBLIC__/ueditor/ueditor.config.js"></script>
                            <script type="text/javascript" charset="utf-8"
                                    src="__PUBLIC__/ueditor/ueditor.all.min.js"></script>
                            <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
                            <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
                            <script type="text/javascript" charset="utf-8"
                                    src="__PUBLIC__/ueditor/lang/zh-cn/zh-cn.js"></script>
                            <script id="editor" name="goods_info" type="text/plain" style="width:800px;height:500px;">
                                {$data[0]['goods_info']}
                            </script>
                        </td>
                    </tr>
                </table>

                <!-- <table width="90%" class="table" align="center" style="display: none;">

                     <tr>
                         <td class="label">商品类型：</td>
                         <td>
                             <select name="type_id" id="type_id">
                                 <option value="0">请选择类型</option>
                                 <volist name="type" id="vo">
                                     <option value="{$vo.id}">{$vo.type_name}</option>
                                 </volist>
                             </select>
                         </td>
                     </tr>
                     <tr>
                         <td colspan="2" id="showAttr"></td>
                     </tr>
                 </table>-->

                <table width="90%" class="table pic" align="center" style="display: none;">

                    <tr>
                        <td colspan="2">
                            <if condition="is_array($data[0]['goods_img'])">
                            <volist name="data[0]['goods_img']" id="vo">
                                <div style="width: 100px;float:left;height:100px;margin:0 10px;"><img src="{$vo}" width="100">

                                </div>

                            </volist>
                                <else/>
                                <div style="width: 100px;float:left;height:100px;margin:0 10px;"><img src="{$data[0]['goods_img']}" width="100">

                                </div>
                                </if>

                        </td>
                    </tr>
                    <tr>
                        <td class="label"></td>
                        <td>
                            <input type="button" name="addNewPic" class="addNewPic" value="增加相册图片">
                        </td>
                    </tr>
                    <tr>
                        <td class="label">相册图片:</td>
                        <td>
                            <input type="file" name="pic[]"/>
                        </td>
                    </tr>
                </table>

                <table width="90%" class="table pic" align="center" style="display: none;">

                    </tr>
                    <tbody id="sx_name">
                    <!-- <tr>
                         <td class="label">商品规格名:</td>
                         <td>
                             <div><input style="width: 200px" type="text"  name="spec_name" value="" />&lt;!&ndash;<input type="button" value="+" onclick="jia1box()">&ndash;&gt;</div>
                             <div style="margin-top: 5px;">
                                 <b>规格值: </b><input type="text"  name="values[]" value=""  style="width: 130px;"/>
                                 <b>价格: </b><input type="text"  name="prices[]" value=""  style="width: 130px;"/>
                                 <b>可抵扣金额: </b><input type="text"  name="integral_price[]" value=""  style="width: 130px;"/>
                                 <b>是否可用: </b>&lt;!&ndash;<input type=""  name="state[0][]" value=""  style="width: 130px;"/>&ndash;&gt;
                                 <input type="checkbox" name="states[]" value="1" checked> 启用  <input type="button" value="+" onclick="jia2box(this)">
                             </div>
                         </td>
                     </tr>-->
                    </tbody>
                </table>

                <div class="button-div">
                    <input type="hidden" id="" name="save_id" value="{$data[0]['goods_id']}"/>
                    <input type="submit" id="submit" value=" 确定 " class="button"/>
                    <input type="reset" value=" 重置 " class="button"/>
                </div>
            </form>
        </div>
    </div>

    <script type="text/javascript" src="/public/Admin/JS/jquery.min.js"></script>
    <script>

        /*  $('#submit').click(function (){
         data = $('#my_form').serialize();

         $.ajax({
         url:"{:U('Goods/add')}",
         type:'post',
         data:data,
         success:function(data){
         $data = JSON.parse(data);
         console.log($data);

         if($data.state == 200){
         alert($data.rel);
         }

         }
         });
         });
         */

        function jia2box(that, id) {
            $(that).parent().parent().append('<div style="margin-top: 5px;">' +
                    ' <b>规格值: </b><input type="text"  name="values[' + id + '][]" value=""  style="width: 130px;"/>' +
                    ' <b>价格: </b><input type="text"  name="prices[' + id + '][]" value=""  style="width: 130px;"/>' +
                    ' <b>可抵扣金额: </b><input type="text"  name="integral_price[' + id + '][]" value=""  style="width: 130px;"/>' +
                    ' <b>是否可用: </b>' +
                    '<input type="checkbox" name="states[' + id + '][]" value="1" checked> 启用 ' +
                    '<input type="button" value="-" onclick="jian2box(this)"></div>');
        }

        function jian2box(that) {
            $(that).parent().remove();
        }

        function alertMsg(that, id) {
            var region_name = $(that).attr("region_name")
            //console.log(region_name);
            if ($('.ssss' + id).is(':checked')) {
                var str = '';
                str += '<tr class = "del' + id + '"><td  class="label">标准定价：</td><td><input type="checkbox" name="normal[' + id + ']"  value="1" checked>是</td></tr>' +
                        '<tr class = "del' + id + '"><td  class="label">所在区域：</td><td><input type="text"   value="' + region_name + '" ></td></tr>' +
                        '<tr class = "del' + id + '"><td class="label">初始价格：</td><td> <input type="text" name="price[' + id + ']" value="" size="20" /></td></tr>' +

                        '<tr class = "del' + id + '"><td class="label">VIP折扣：</td><td>' +
                        '<div style="margin-top: 5px;"><b>普通折扣: </b><input type="text"  name="vip_discount[' + id + '][]" value=""  style="width: 130px;"/></div><div style="margin-top: 5px;"><b>VIP1折扣: </b><input type="text"  name="vip_discount[' + id + '][]" value=""  style="width: 130px;"/></div>' +
                        '<div style="margin-top: 5px;"><b>VIP2折扣: </b><input type="text"  name="vip_discount[' + id + '][]" value=""  style="width: 130px;"/></div>' +
                        '<div style="margin-top: 5px;"><b>VIP3折扣: </b><input type="text"  name="vip_discount[' + id + '][]" value=""  style="width: 130px;"/></div>' +
                        '<div style="margin-top: 5px;"><b>VIP4折扣: </b><input type="text"  name="vip_discount[' + id + '][]" value=""  style="width: 130px;"/></div>' +
                        '<div style="margin-top: 5px;"><b>VIP5折扣: </b><input type="text"  name="vip_discount[' + id + '][]" value=""  style="width: 130px;"/></div>' +
                        '<div style="margin-top: 5px;"><b>VIP6折扣: </b><input type="text"  name="vip_discount[' + id + '][]" value=""  style="width: 130px;"/></div></td></tr>' +
                        '<tr class = "del' + id + '"><td class="label">商品规格名:</td><td><div><input style="width: 200px" type="text"  name="spec_name[' + id + '][]" value="" /></div>' +
                        '<div style="margin-top: 5px;"><b>规格值: </b><input type="text"  name="values[' + id + '][]" value=""  style="width: 130px;"/><b>价格: </b><input type="text"  name="prices[' + id + '][]" value=""  style="width: 130px;"/>' +
                        '<b>可抵扣金额: </b><input type="text"  name="integral_price[' + id + '][]" value=""  style="width: 130px;"/><b>是否可用: </b>' +
                        '<input type="checkbox" name="states[' + id + '][]" value="1" checked> 启用  <input type="button"   value="+" onclick="jia2box(this,' + id + ')"></div> </td></tr>';
                $('#sss').after(str);
            } else {

                $('.del' + id).remove();
            }


        }
    </script>
</block>
<block name="js">
    <script type="text/javascript">

        //实例化编辑器
        //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
        var ue = UE.getEditor('editor');

        //实现扩展分类的点击按钮增加select选择框
        $('#addExtCate').click(function () {
            //复制select选择框
            var newSelect = $(this).next().clone();
            //将内容写入到td中
            $(this).parent().append(newSelect);
        });
        //实现选项卡切换
        $('#tabbar-div p span').click(function () {
            //将所有的table设置为隐藏
            $('.table').hide();
            //将当前点击的选项卡对应的内容设置为显示
            var i = $(this).index();
            $('.table').eq(i).show();
        });

        $('#type_id').change(function () {
            //获得当前被选中的类型标识
            var type_id = $(this).val();
            $.ajax({
                url: "{:U('showAttr')}",
                data: {type_id: type_id},
                type: 'post',
                success: function (msg) {
                    $("#showAttr").html(msg);

                }
            });
        });

        function clonethis(obj) {
            //获取当前tr的对象
            var current = $(obj).parent().parent();
            if ($(obj).html() == '[+]') {
                //复制当前的td
                var newtr = current.clone();
                //将当前的特殊符号改为[-]
                newtr.find('a').html('[-]');
                current.after(newtr);
            } else {
                current.remove();
            }
        }

        //实现点击按钮增加图片上传
        $('.addNewPic').click(function () {
            //将上传框对应的tr进行复制
            var newfile = $(this).parent().parent().next().clone();
            //追加上传框到table
            $('.pic').append(newfile);
        });


    </script>
</block>
